/**
 * @param {number[]} nums
 * @return {number}
 */
var removeDuplicates = function (nums) {
  let len = nums.length
  let count = 0, length = 0, left = 0, right = 0
  while (right < len) {
    if (nums[left] == nums[right]) {
      if (count != 2) {
        count++
        length++
        right++
      } else {
        nums.splice(left + count, 1)
        len--
      }


    } else {
      left = right
      count = 0
    }


  }

  return length
};

removeDuplicates([0, 0, 1, 1, 1, 1, 2, 3, 3])